﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using System.Threading;

namespace VDataAdapter
{
    class TransactionWorker : Worker
    {
        protected VdataCommunicator _sender;

        public TransactionWorker(ManualResetEvent waitFirstTime, ManualResetEvent endRecovery, VdataCommunicator sender)
            : base(waitFirstTime, endRecovery)
        {
            _sender = sender;
        }
         
        /// <summary>
        /// Send data to queue
        /// </summary>
        /// <param name="data"></param>
        protected override void DoWork(object data)
        {
            List<PriceLibrary.ChartService.Transaction> dataToSend;

            if(!typeof(List<PriceLibrary.ChartService.Transaction>).Equals(data.GetType()))
                throw new InvalidCastException("Cant convert to List<Transaction>");
            
            dataToSend = (List<PriceLibrary.ChartService.Transaction>)data;

            foreach (PriceLibrary.ChartService.Transaction transaction in dataToSend)
                _sender.SendTransaction(transaction);            
        }
    
    }
}
